﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x02000564 RID: 1380
	public class AnimeCategoryList : MonoBehaviour
	{
		// Token: 0x17000446 RID: 1094
		// (get) Token: 0x06002336 RID: 9014 RVA: 0x000D486C File Offset: 0x000D2A6C
		// (set) Token: 0x06002337 RID: 9015 RVA: 0x000D487C File Offset: 0x000D2A7C
		public bool active
		{
			get
			{
				return base.gameObject.activeSelf;
			}
			set
			{
				if (base.gameObject.activeSelf != value)
				{
					base.gameObject.SetActive(value);
					if (!base.gameObject.activeSelf)
					{
						this.animeList.active = false;
					}
				}
			}
		}

		// Token: 0x06002338 RID: 9016 RVA: 0x000D48B8 File Offset: 0x000D2AB8
		public void InitList(AnimeGroupList.SEX _sex, int _group)
		{
			int childCount = this.transformRoot.childCount;
			for (int i = 0; i < childCount; i++)
			{
				UnityEngine.Object.Destroy(this.transformRoot.GetChild(i).gameObject);
			}
			this.transformRoot.DetachChildren();
			this.scrollRect.verticalNormalizedPosition = 1f;
			this.dicNode = new Dictionary<int, Image>();
			foreach (KeyValuePair<int, string> keyValuePair in ((_sex != AnimeGroupList.SEX.Male) ? Singleton<Info>.Instance.dicFAGroupCategory[_group].dicCategory : Singleton<Info>.Instance.dicMAGroupCategory[_group].dicCategory))
			{
				if (this.CheckCategory(_group, keyValuePair.Key, (_sex != AnimeGroupList.SEX.Male) ? Singleton<Info>.Instance.dicFemaleAnimeLoadInfo : Singleton<Info>.Instance.dicMaleAnimeLoadInfo))
				{
					GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.objectPrefab);
					if (!gameObject.activeSelf)
					{
						gameObject.SetActive(true);
					}
					gameObject.transform.SetParent(this.transformRoot, false);
					GameSceneNode component = gameObject.GetComponent<GameSceneNode>();
					int no = keyValuePair.Key;
					component.AddActionToButton(delegate
					{
						this.OnSelect(no);
					});
					component.text = keyValuePair.Value;
					this.dicNode.Add(keyValuePair.Key, gameObject.GetComponent<Image>());
				}
			}
			this.select = -1;
			this.group = _group;
			this.sex = _sex;
			this.active = true;
			this.animeList.active = false;
		}

		// Token: 0x06002339 RID: 9017 RVA: 0x000D4A8C File Offset: 0x000D2C8C
		private bool CheckCategory(int _group, int _category, Dictionary<int, Dictionary<int, Dictionary<int, Info.AnimeLoadInfo>>> _dic)
		{
			Dictionary<int, Dictionary<int, Info.AnimeLoadInfo>> dictionary = null;
			return _dic.TryGetValue(_group, out dictionary) && dictionary.ContainsKey(_category);
		}

		// Token: 0x0600233A RID: 9018 RVA: 0x000D4AB4 File Offset: 0x000D2CB4
		private void OnSelect(int _no)
		{
			int key = this.select;
			if (Utility.SetStruct<int>(ref this.select, _no))
			{
				this.animeList.InitList(this.sex, this.group, _no);
				Image image = null;
				if (this.dicNode.TryGetValue(key, out image) && image != null)
				{
					image.color = Color.white;
				}
				image = null;
				if (this.dicNode.TryGetValue(this.select, out image) && image != null)
				{
					image.color = Color.green;
				}
			}
		}

		// Token: 0x04002428 RID: 9256
		[SerializeField]
		private Transform transformRoot;

		// Token: 0x04002429 RID: 9257
		[SerializeField]
		private GameObject objectPrefab;

		// Token: 0x0400242A RID: 9258
		[SerializeField]
		private ScrollRect scrollRect;

		// Token: 0x0400242B RID: 9259
		[SerializeField]
		private AnimeList animeList;

		// Token: 0x0400242C RID: 9260
		private AnimeGroupList.SEX sex = AnimeGroupList.SEX.Unknown;

		// Token: 0x0400242D RID: 9261
		private int group = -1;

		// Token: 0x0400242E RID: 9262
		private int select = -1;

		// Token: 0x0400242F RID: 9263
		private Dictionary<int, Image> dicNode;
	}
}
